
// implements the base class for the patterns
public class PLPattern {
	private String mName = null;
	
	public PLPattern() {	}
	public PLPattern(String name) { mName = name;}

	public float BuildResponse(PLShape query, PLOutShape  outResponse) { return 0f;}	
	
	// the resulting float value reflects the confidence in response, 
	// if the response perfectly satisfies the pattern, 1 is returned, values less than 1 reflect 
	// decrease in confidence in the response.
	// if the confidence is too low, the pattern also returns a new shape that better fits the pattern.
	public float ValidateResponse(PLShape query, PLShape response, PLOutShape  outBetterMatch) {return 0f;}

	public float ImproveResponse(PLShape query, PLOutShape outResponse, PLShape  betterMatch) {return 0f;}
	
	public static PLPattern GetPatternByName(String name) {
		int nameCode = name.hashCode();
		
		if (nameCode == "Parallel".hashCode()) {
			return new PLPatternParallel();
		} 
		else if (nameCode == "Intersection".hashCode()) {
			return new PLPatternIntersection();
		} 
		else if (nameCode == "Above".hashCode()) {
			return new PLPatternAboveOf();
		}
		else if (nameCode == "Below".hashCode()) {
			return new PLPatternBelowOf();
		}
		else if (nameCode == "Left".hashCode()) {
			return new PLPatternLeftOf();
		}
		else if (nameCode == "Right".hashCode()) {
			return new PLPatternRightOf();
		}
		else if (nameCode == "Random".hashCode()) {
			return new PLPatternRandom();
		} 
		else {
			PLDebug.Err("Pattern %s unknown", name);
		}	

		return null;
	}

	public void SetName(String name) {mName = name;}
	public String GetName() {return mName;}

	// returns all the patterns implemented
	public static PLPattern[] GetAllPatterns()  {
		PLPattern[] mPatterns = new PLPattern[7];
		mPatterns[0] = new PLPatternParallel();
		mPatterns[1] = new PLPatternIntersection();
		mPatterns[2] = new PLPatternAboveOf();
		mPatterns[3] = new PLPatternBelowOf();
		mPatterns[4] = new PLPatternLeftOf();
		mPatterns[5] = new PLPatternRightOf();
		mPatterns[6] = new PLPatternRandom();	
		return mPatterns;
	}	
}
